

package com.hexinfo.dmpro.dev.data.transfer.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hexinfo.dmpro.common.annotation.AnonymousAccess;
import com.hexinfo.dmpro.dev.data.transfer.model.DevDataImportTask;
import com.hexinfo.dmpro.dev.data.transfer.service.IDevDataImportTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;


/**
 * 总导入任务表
 *
 * @author yyh.huang
 * @date 2023-10-25 19:18:17
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/api/dev/data/import/task" )
@Api(value = "devdataimporttask", tags = "总导入任务表管理")
public class DevDataImportTaskController {

    private final IDevDataImportTaskService devDataImportTaskService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param devDataImportTask 总导入任务表
     * WrapperEnhancer.like(devDataImportTask); //自动拼接存在值sql的方法
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    public ResponseEntity<Object> getDevDataImportTaskPage(Page page, DevDataImportTask devDataImportTask) {
        return ResponseEntity.ok(devDataImportTaskService.queryList(page,devDataImportTask));
    }


    /**
     * 通过id查询总导入任务表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    public ResponseEntity<Object> getById(@PathVariable("id" ) String id) {
        return ResponseEntity.ok(devDataImportTaskService.getById(id));
    }

    /**
     * 新增总导入任务表
     * @param devDataImportTask 总导入任务表
     * @return R
     */
    @ApiOperation(value = "新增总导入任务表", notes = "新增总导入任务表")
    @PostMapping
    @AnonymousAccess
    public ResponseEntity<Object> save(@RequestBody DevDataImportTask devDataImportTask) {
        devDataImportTaskService.createTask(devDataImportTask);
        return ResponseEntity.ok("ok");
    }

    /**
     * 修改总导入任务表
     * @param devDataImportTask 总导入任务表
     * @return R
     */
    @ApiOperation(value = "修改总导入任务表", notes = "修改总导入任务表")
    @PutMapping
    public ResponseEntity<Object> updateById(@RequestBody DevDataImportTask devDataImportTask) {
        return ResponseEntity.ok(devDataImportTaskService.updateById(devDataImportTask));
    }

    /**
     * 通过id删除总导入任务表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除总导入任务表", notes = "通过id删除总导入任务表")
    @DeleteMapping("/{id}" )
    public ResponseEntity<Object> removeById(@PathVariable String id) {
        return ResponseEntity.ok(devDataImportTaskService.removeById(id));
    }

    @ApiOperation(value = "服务重启任务继续执行", notes = "服务重启任务继续执行")
    @PutMapping(value = "/continue/run/{id}")
    public ResponseEntity<Object> continueRunById(@PathVariable("id") String id) {
        log.info("服务重启任务继续执行：{}", id);
        devDataImportTaskService.continueRunById(id);
        return ResponseEntity.ok("ok");
    }

    @ApiOperation(value = "开发数据导入任务暂停", notes = "开发数据导入任务暂停")
    @PutMapping("/suspend")
    @AnonymousAccess
    public ResponseEntity<Object> suspend(@RequestBody @NotNull List<String> ids) {
        log.info("开发数据导入任务暂停：{}", StrUtil.join(",", ids));
        devDataImportTaskService.suspend(ids);
        return ResponseEntity.ok("ok");
    }

    @ApiOperation(value = "开发数据导入任务中止", notes = "开发数据导入任务中止")
    @PutMapping("/abolish")
    public ResponseEntity<Object> abolish(@RequestBody @NotNull List<String> ids) {
        log.info("开发数据导出任务中止：{}", StrUtil.join(",", ids));
        devDataImportTaskService.abolish(ids);
        return ResponseEntity.ok("ok");
    }

    @ApiOperation(value = "开发数据导入任务暂停后重启", notes = "开发数据导入任务暂停后重启")
    @PutMapping("/restart")
    @AnonymousAccess
    public ResponseEntity<Object> restart(@RequestBody @NotNull List<String> ids) {
        log.info("开发数据导入任务暂停后重启：{}", StrUtil.join(",", ids));
        devDataImportTaskService.restart(ids);
        return ResponseEntity.ok("ok");
    }

}
